package leetcode.problems;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by gmwang on 2018/7/25
 */
public class _0730TransposeMatrix {
    /**
     *
     * Given a matrix A, return the transpose of A.
     *给定矩阵A，返回转置A。
     *
     * The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and column indices of the matrix.
     *矩阵的转置是在其主对角线上翻转的矩阵，切换矩阵的行和列索引。
     *
     * Example 1:
     *
     * Input: [[1,2,3],[4,5,6],[7,8,9]]
     * Output: [[1,4,7],[2,5,8],[3,6,9]]
     * Example 2:
     *
     * Input: [[1,2,3],[4,5,6]]
     * Output: [[1,4],[2,5],[3,6]]
     *
     * Note:
     *
     * 1 <= A.length <= 1000
     * 1 <= A[0].length <= 1000
     */
    /**
     * 先比较某个值之前都是升序，再比较某个值之后都是降序
     * @param left,right
     * @return
     */
    public List<Integer> selfDividingNumbers(int left, int right) {
        List<Integer> list = new ArrayList<>();
        for(int i = left;i <= right;i ++){
            if((i+"").contains("0")) continue;
            if(isSelfDividingNumber(i)){
                list.add(i);
            }
        }
        return list;
    }

    /**
     * 判断是否是自分割数
     * @param selfDividingNumber
     * @return
     */
    public boolean isSelfDividingNumber(int selfDividingNumber){
        int flag = 0;
        String selfNumber = selfDividingNumber+"";
        for(int x = 0; x < selfNumber.length();x++){
            //每一位数都除尽
            if(selfDividingNumber % Integer.parseInt(selfNumber.substring(x,x+1)) == 0) flag++;
        }
        return flag==(selfDividingNumber+"").length()?true:false;
    }
    @Test
    public void test() {
        int left =1 ,right =22;
        List<Integer> res = selfDividingNumbers(left,right);
        System.out.println(res);
//        System.out.println((2+"").length());
    }
}
